package com.mazaiting.blog.dao

import com.mazaiting.blog.domain.Visitor
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
import javax.annotation.Resource


@RunWith(SpringRunner::class)
@EnableAutoConfiguration
@SpringBootTest
class VisitorDaoTest {

    @Resource
    private lateinit var visitorDao: VisitorDao

    @Test
    fun selectByRemoteAddr() {
        val visitor = visitorDao.selectByRemoteAddr("0:0:0:0:0:0:0:1")
        println(visitor)
    }

    @Test
    fun addVisitor() {
        val visitor = Visitor("0:0:0:0:0:0:0:3", "0:0:0:0:0:0:0:3", 53733)
        val id = visitorDao.addVisitor(visitor)
        println(id)
    }

    @Test
    fun updateVisitor() {
        val visitor = visitorDao.selectByRemoteAddr("0:0:0:0:0:0:0:3")
        if (null != visitor) {
            visitor.visitorNum += 1
            val id = visitorDao.updateVisitor(visitor)
            println(id)
        }
    }

}